// 有效的数独

package Leetcode;

import java.util.HashMap;
import java.util.Map;

class solution_036 {
    public boolean isValidSudoku(char[][] board) {
        Map<Character, Integer> batch = new HashMap<>();
        int length = board[0].length;

        for (int i = 0; i < length; i++){
            for (int j = 0; j < length; j++) {
                if (board[i][j] != '.') {
                    if (batch.containsKey(board[i][j]) == false)
                        batch.put(board[i][j], i + j);
                    else
                        return false;
                }
            }
            batch.clear();
        }
        for (int i = 0; i < length; i++){
            for (int j = 0; j < length; j++) {
                if (board[j][i] != '.') {
                    if (batch.containsKey(board[j][i]) == false)
                        batch.put(board[j][i], i + j);
                    else
                        return false;
                }
            }
            batch.clear();
        }
        for (int i = 0; i < length; i = i + 3)
            for (int j = 0; j < length; j = j + 3) {
                for (int m = i; m < i + 3; m++)
                    for (int n = j; n < j + 3; n++) {
                        if (board[m][n] != '.') {
                            if (batch.containsKey(board[m][n]) == false)
                                batch.put(board[m][n], m + n);
                            else
                                return false;
                        }
                    }
                batch.clear();
            }
        return true;
    }
}

public class Solution036 {

}